//
//  CityInfo.m
//  FinancialStore
//
//  Created by zhenqiu on 16/7/21.
//  Copyright © 2016年 zhenqiu. All rights reserved.
//

#import "CityInfo.h"

@implementation CityInfo
@synthesize zone_id;
@synthesize zone_name;
@synthesize CN;
@synthesize EN;
@synthesize letter;
@synthesize s_EN;


+(CityInfo*)getCacheCity{
    
    
    id cityDic = [[CacheHelper getInstance] getCityInfo];
    
    if(cityDic){
        
        CityInfo * city = [self mj_objectWithKeyValues:cityDic];
        return city;
    }
   
    return nil;
    
}



+(NSArray*)getCityList:(id)data{
    
    NSArray * dataArray = [CityInfo mj_objectArrayWithKeyValuesArray:data];
    return dataArray;
}

+(NSArray*)getAllCityList:(id)data{
    
    NSMutableArray * dataArray = [NSMutableArray arrayWithCapacity:22];
    
    NSArray * letters = [data valueForKey:@"letters"];
    
    for (NSInteger i = 0; i < [letters count]; i ++) {
        
        NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithCapacity:2];
        NSString * key = [letters objectAtIndex:i];
        id  subs = [CityInfo getCityList:[[data valueForKey:@"items"] valueForKey:key]];
        
        [dic setValue:key forKey:@"key"];
        [dic setValue:subs forKey:@"subs"];
        
        [dataArray addObject:dic];
    }
    return dataArray;
 
}

+(NSArray*)getHotCityList:(id)data{
    
    return [self getCityList:data];
}


// cache
+(void)cacheCityList:(id)data{
    
    [[CacheHelper getInstance] setCacheValue:data forKey:CITY_INFO_LIST_KEY];
}

+(NSArray*)getCacheAllCityList{
    
    id cacheData = [[CacheHelper getInstance] getCacheValue:CITY_INFO_LIST_KEY];
    
    if(cacheData){
        
        return [self getAllCityList:cacheData];
    }
    
    return nil;
}

+(NSArray*)getCacheHotCityList{
    
    id cacheData = [[CacheHelper getInstance] getCacheValue:CITY_INFO_LIST_KEY];
    cacheData = [cacheData valueForKey:@"hots"];
    if(cacheData){
        
        return [self getHotCityList:cacheData];
    }

    return nil;
}

+(NSArray*)getCacheLetterArray{
    
    id cacheData = [[CacheHelper getInstance] getCacheValue:CITY_INFO_LIST_KEY];
    if(cacheData){
        
        return [cacheData valueForKey:@"letters"];
    }

    
    return nil;
}


@end
